import { SettingsModel } from 'server/models/Settings'
import { successResponse, errorResponse } from 'server/utils/response'

export default defineEventHandler(async (event) => {
  try {
    const analytics = await SettingsModel.getAnalytics()
    
    if (!analytics) {
      return successResponse({
        headCode: '',
        bodyCode: '',
        enabled: false
      }, '获取统计代码信息成功')
    }

    return successResponse(analytics, '获取统计代码信息成功')
  } catch (error) {
    console.error('获取统计代码信息失败:', error)
    return errorResponse(
      '获取统计代码信息失败',
      error instanceof Error ? error.message : '未知错误'
    )
  }
})